package main

import (
    "os"
    "github.com/mattn/go-gtk/gtk"
    "path"
    "fmt"
)

func main() {
    gtk.Init(&os.Args)
    window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
    window.SetTitle("GTK Go!")
    window.Connect("destroy", func() {
        println("got destroy!")
        gtk.MainQuit()
    })

    //--------------------------------------------------------
    // GtkVBox
    //--------------------------------------------------------
    vbox := gtk.VBox(false, 1)

    //--------------------------------------------------------
    // GtkImage
    //--------------------------------------------------------
    dir, _ := path.Split(os.Args[0])
    imagefile := path.Join(dir, "../github.com/mattn/go-gtk/data/go-gtk-logo.png")
    fmt.Println("--> ", imagefile)
    label := gtk.Label("Go Binding for GTK")
    vbox.PackStart(label, false, true, 0)

    entry := gtk.Entry()
    entry.SetText("Hello world")
    vbox.Add(entry)

    image := gtk.ImageFromFile(imagefile)
    vbox.Add(image)

    //--------------------------------------------------------
    // GtkHBox
    //--------------------------------------------------------
    buttons := gtk.HBox(false, 1)

    //--------------------------------------------------------
    // GtkButton
    //--------------------------------------------------------
    button := gtk.ButtonWithLabel("Button with label")
    button.Clicked(func() {
        print("button clicked: ", button.GetLabel(), "\n")
        dialog := gtk.MessageDialog(
            button.GetTopLevelAsWindow(),
            gtk.GTK_DIALOG_MODAL,
            gtk.GTK_MESSAGE_INFO,
            gtk.GTK_BUTTONS_OK,
            entry.GetText())
        dialog.Response(func() {
            println("Dialog OK!")
        })
        dialog.Run()
        dialog.Destroy()
    })
    buttons.Add(button)

    //--------------------------------------------------------
    // GtkFontButton
    //--------------------------------------------------------
    fontbutton := gtk.FontButton()
    fontbutton.Connect("font-set", func() {
        print("title: ", fontbutton.GetTitle(), "\n")
        print("fontname: ", fontbutton.GetFontName(), "\n")
        print("use_size: ", fontbutton.GetUseSize(), "\n")
        print("show_size: ", fontbutton.GetShowSize(), "\n")
    })
    buttons.Add(fontbutton)
    vbox.Add(buttons)

    buttons = gtk.HBox(false, 1)

    //--------------------------------------------------------
    // GtkToggleButton
    //--------------------------------------------------------
    togglebutton := gtk.ToggleButtonWithLabel("ToggleButton with label")
    togglebutton.Connect("toggled", func() {
        if togglebutton.GetActive() {
            togglebutton.SetLabel("ToggleButton ON!")
        } else {
            togglebutton.SetLabel("ToggleButton OFF!")
        }
    })
    buttons.Add(togglebutton)

    //--------------------------------------------------------
    // GtkCheckButton
    //--------------------------------------------------------
    checkbutton := gtk.CheckButtonWithLabel("CheckButton with label")
    checkbutton.Connect("toggled", func() {
        if checkbutton.GetActive() {
            checkbutton.SetLabel("CheckButton CHECKED!")
        } else {
            checkbutton.SetLabel("CheckButton UNCHECKED!")
        }
    })
    buttons.Add(checkbutton)
    vbox.Add(buttons)

    combos := gtk.HBox(false, 1)

    comboboxentry := gtk.ComboBoxEntryNewText()
    comboboxentry.Connect("changed", func() {
        //comboboxentry...
    })
    combos.Add(comboboxentry)
    vbox.Add(combos)

    window.Add(vbox)

    window.ShowAll()
    gtk.Main()
}
